 #include <OneWire.h>
 #include <DallasTemperature.h>
 // 数据线已插入Arduino上的端口2
 #define ONE_WIRE_BUS 2
 // 设置oneWire实例以与任何oneWire设备通信
 OneWire oneWire(ONE_WIRE_BUS);
 // 通过我们的oneWire参考达拉斯温度。
 DallasTemperature sensors(&oneWire);
 // 用于保存设备地址的变量
 DeviceAddress Thermometer;
 int deviceCount = 0;
 void setup(void)
 {
   // 启动串行端口
   Serial.begin(9600);
   // 启动库
   sensors.begin();
   // 在总线上定位设备
   Serial.println("Locating devices...");
   Serial.print("Found ");
   deviceCount = sensors.getDeviceCount();
   Serial.print(deviceCount, DEC);
   Serial.println(" devices.");
   Serial.println("");
   
   Serial.println("Printing addresses...");
   for (int i = 0;  i < deviceCount;  i++)
   {
     Serial.print("Sensor ");
     Serial.print(i+1);
     Serial.print(" : ");
     sensors.getAddress(Thermometer, i);
     printAddress(Thermometer);
   }
 }
 void loop(void)
 {}
 void printAddress(DeviceAddress deviceAddress)
 { 
   for (uint8_t i = 0; i < 8; i++)
   {
     Serial.print("0x");
     if (deviceAddress[i] < 0x10) Serial.print("0");
     Serial.print(deviceAddress[i], HEX);
     if (i < 7) Serial.print(", ");
   }
   Serial.println("");
 }